﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using IHISCETeim.Library;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using IHISCETeim.Model;

namespace IHISCETeim.DAL
{
    public class MBaoYangDAL
    {
        public static int Add(MBaoYangInfo obj)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("MBaoYang_Add", obj.SQR,obj.JXS,obj.YHM,obj.JX,obj.JH,obj.ZSYY,obj.PJZL,obj.SL,obj.SQSJ,obj.ZXSJ,obj.CKSJ,obj.CKDH,obj.PZH,obj.BB_ZHHTH,obj.ZH_RQ,obj.ZH_DD,obj.ZH_JJSJ,obj.QT_XSRQ,obj.QT_XSHTH,obj.QT_XSJH,obj.QT_XSKH,obj.QT_JHRQ,obj.QT_JHHTH,obj.QT_JHJH,obj.BZ);
            return Convert.ToInt32(DB.ExecuteScalar(dbCommand));
        }
        public static bool Delete(int id)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("MBaoYang_Delete", id);
            try
            {
                DB.ExecuteScalar(dbCommand);
                return true;
            }
            catch
            {
                return false;
            }
        }
        public static IDataReader GetByID(int id)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("MBaoYang_GetByID", id);
            return DB.ExecuteReader(dbCommand);
        }

        public static IDataReader GetByJH(string JH)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("MBaoYang_GetByJH", JH);
            return DB.ExecuteReader(dbCommand);
        }

        public static DataTable GetPagination(string whereSql, int PageIndex, int PageSize, string Sort, ref int TotalCount)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("MBaoYang_GetPagination");
            DB.AddInParameter(dbCommand, "whereSql", DbType.String, whereSql);
            DB.AddInParameter(dbCommand, "PageIndex", DbType.Int32, PageIndex);
            DB.AddInParameter(dbCommand, "PageSize", DbType.Int32, PageSize);
            DB.AddInParameter(dbCommand, "Sort", DbType.String, Sort);
            DB.AddOutParameter(dbCommand, "TotalCount", DbType.Int32, 8);
            DataTable dt = DB.ExecuteDataSet(dbCommand).Tables[0];

            TotalCount = Convert.ToInt32(DB.GetParameterValue(dbCommand, "TotalCount"));
            return dt;
        }
        public static bool Update(MBaoYangInfo obj)
        {
            Database DB = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand = DB.GetStoredProcCommand("MBaoYang_Update",obj.id,obj.SQR,obj.JXS,obj.YHM,obj.JX,obj.JH,obj.ZSYY,obj.PJZL,obj.SL,obj.SQSJ,obj.ZXSJ,obj.CKSJ,obj.CKDH,obj.PZH,obj.BB_ZHHTH,obj.ZH_RQ,obj.ZH_DD,obj.ZH_JJSJ,obj.QT_XSRQ,obj.QT_XSHTH,obj.QT_XSJH,obj.QT_XSKH,obj.QT_JHRQ,obj.QT_JHHTH,obj.QT_JHJH,obj.BZ);
            try
            {
                DB.ExecuteScalar(dbCommand);
                return true;
            }
            catch (Exception exc)
            {
                return false;
            }
        }
    }
}
